FUNCTION GLOBAL_SUMMOD_2DARR &
& (ix0, ix1, iy0, iy1, &
& i0, i1, j0, j1, &
& comm3d, array, parallel)

!use MPI
use MPI_VARIABLES, only : &
& global_summod_2darr_indic
use TIMING_MOD, only : &
& proc_time

implicit none

include 'mpif.h'

real(8) :: GLOBAL_SUMMOD_2DARR

! Input/output variables
integer(4), intent(in) :: ix0, ix1, iy0, iy1
integer(4), intent(in) :: i0, i1, j0, j1
integer(4), intent(in) :: comm3d

real(8), intent(in) :: array(ix0:ix1,iy0:iy1)

logical, intent(in) :: parallel

! Local variables
integer(4) :: ix, iy
integer(4) :: ierr

real(8) :: work
real(8) :: pr_time, pro_time

work = 0.
do iy = j0, j1
  do ix = i0, i1
    work = work + dabs(array(ix,iy))
  enddo
enddo

if (parallel) then

!  pr_time = MPI_WTIME()
  call cpu_time(pr_time)

  call MPI_ALLREDUCE(work, GLOBAL_SUMMOD_2DARR, 1, MPI_DOUBLE_PRECISION, &
  & MPI_SUM, comm3d, ierr)

!  proc_time(global_summod_2darr_indic,2) = proc_time(global_summod_2darr_indic,2) + &
!  & MPI_WTIME() - pr_time

  call cpu_time(pro_time)
  proc_time(global_summod_2darr_indic,2) = proc_time(global_summod_2darr_indic,2) + &
  & pro_time - pr_time

else
  GLOBAL_SUMMOD_2DARR = work
endif


END FUNCTION GLOBAL_SUMMOD_2DARR
